package com.verisette.ncos.persistence.domain;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.corp.agi.service.bean.UserBean;

import com.verisette.ncos.common.CommonUtil;


/**
 * The persistent class for the MASTER_USER_PROFILE database table.
 * 
 */
@Entity
@Table(name="MASTER_USER_PROFILE")
public class MasterUserProfile implements Serializable, UserBean {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="USP_ID")
	private Integer uspId;

	@Column(name="USP_CREATED_BY")
	private String uspCreatedBy;

	@Column(name="USP_CREATED_DATE")
	private Timestamp uspCreatedDate;

	@Column(name="USP_EMAIL")
	private String uspEmail;

	@Column(name="USP_EXPIRE_DATE")
	private Timestamp uspExpireDate;

	@Column(name="USP_FNAME")
	private String uspFname;

	@Column(name="USP_FORCE_CHNG_PWD_FLAG")
	private String uspForceChngPwdFlag;

	@Column(name="USP_LAST_ACCESS_DATE")
	private Timestamp uspLastAccessDate;

	@Column(name="USP_LAST_UPDATED_BY")
	private String uspLastUpdatedBy;

	@Column(name="USP_LAST_UPDATED_DATE")
	private Timestamp uspLastUpdatedDate;

	@Column(name="USP_LNAME")
	private String uspLname;

	@Column(name="USP_LOCK_FLAG")
	private String uspLockFlag;

	@Column(name="USP_MNAME")
	private String uspMname;

	@Column(name="USP_MOBILE_NO")
	private String uspMobileNo;

	@Column(name="USP_PASSWORD")
	private String uspPassword;

	@Column(name="USP_STATUS")
	private String uspStatus;

	@Column(name="USP_TEL_NO")
	private String uspTelNo;

	@Column(name="USP_TITLE")
	private String uspTitle;

	@Column(name="USP_USER_NAME")
	private String uspUserName;

	@Column(name="USP_WRONG_LOGIN_COUNTER")
	private Short uspWrongLoginCounter;
	
	//bi-directional many-to-one association to MasterBranch
//	@ManyToOne(fetch=FetchType.LAZY)
	@ManyToOne
	@JoinColumn(name="BRANCH_ID")
	private MasterBranch masterBranch;

	//bi-directional many-to-one association to MasterCompany
//	@ManyToOne(fetch=FetchType.LAZY)
	@ManyToOne
	@JoinColumn(name="COMPANY_ID")
	private MasterCompany masterCompany;
	
	@OneToOne(mappedBy="masterUserProfile")
	private MasterTemplateGroupToUsp masterTemplateGroupToUsp;
	
	@Column(name="APPROVER_USP_ID")
	private Integer approverUspId;

    public MasterUserProfile() {
    }
    
    //Custom method #########################
    public String getFullNameTh(){
    	StringBuilder fullNameBd = new StringBuilder();
    	fullNameBd.append(uspFname);
    	fullNameBd.append(" ");
    	fullNameBd.append(uspLname);
    	return fullNameBd.toString();
    }
    public String getFullNameWithTitleTh(){
    	StringBuilder fullNameWithTitleBd = new StringBuilder();
    	fullNameWithTitleBd.append("คุณ ").append(getFullNameTh());
    	return fullNameWithTitleBd.toString();
    }
    //Custom method #########################
    
	public Integer getUspId() {
		return uspId;
	}

	public void setUspId(Integer uspId) {
		this.uspId = uspId;
	}

	public String getUspCreatedBy() {
		return this.uspCreatedBy;
	}

	public void setUspCreatedBy(String uspCreatedBy) {
		this.uspCreatedBy = uspCreatedBy;
	}

	public Timestamp getUspCreatedDate() {
		return this.uspCreatedDate;
	}

	public void setUspCreatedDate(Timestamp uspCreatedDate) {
		this.uspCreatedDate = uspCreatedDate;
	}

	public String getUspEmail() {
		return this.uspEmail;
	}

	public void setUspEmail(String uspEmail) {
		this.uspEmail = uspEmail;
	}

	public Timestamp getUspExpireDate() {
		return this.uspExpireDate;
	}
	
	public String getUspExpireDateFormatted() {
		String uspExpireDateStr = "";
		if(this.uspExpireDate!=null){
			uspExpireDateStr = CommonUtil.date2StrFormat(uspExpireDate, "dd/MM/yyyy HH:mm:sss");
		}
		return uspExpireDateStr;
	}
	
	public void setUspExpireDate(Timestamp uspExpireDate) {
		this.uspExpireDate = uspExpireDate;
	}

	public String getUspFname() {
		return this.uspFname;
	}

	public void setUspFname(String uspFname) {
		this.uspFname = uspFname;
	}

	public String getUspForceChngPwdFlag() {
		return this.uspForceChngPwdFlag;
	}

	public void setUspForceChngPwdFlag(String uspForceChngPwdFlag) {
		this.uspForceChngPwdFlag = uspForceChngPwdFlag;
	}

	public String getUspLastAccessDateFormatted() {
		String uspLastAccessDateStr = "";
		if(this.uspLastAccessDate!=null){
			uspLastAccessDateStr = CommonUtil.date2StrFormat(this.uspLastAccessDate, "dd/MM/yyyy HH:mm:sss");
		}
		return uspLastAccessDateStr;
	}
	
	public Timestamp getUspLastAccessDate() {
		return this.uspLastAccessDate;
	}

	public void setUspLastAccessDate(Timestamp uspLastAccessDate) {
		this.uspLastAccessDate = uspLastAccessDate;
	}

	public String getUspLastUpdatedBy() {
		return this.uspLastUpdatedBy;
	}

	public void setUspLastUpdatedBy(String uspLastUpdatedBy) {
		this.uspLastUpdatedBy = uspLastUpdatedBy;
	}

	public Timestamp getUspLastUpdatedDate() {
		return this.uspLastUpdatedDate;
	}

	public void setUspLastUpdatedDate(Timestamp uspLastUpdatedDate) {
		this.uspLastUpdatedDate = uspLastUpdatedDate;
	}

	public String getUspLname() {
		return this.uspLname;
	}

	public void setUspLname(String uspLname) {
		this.uspLname = uspLname;
	}

	public String getUspLockFlag() {
		return this.uspLockFlag;
	}

	public void setUspLockFlag(String uspLockFlag) {
		this.uspLockFlag = uspLockFlag;
	}

	public String getUspMname() {
		return this.uspMname;
	}

	public void setUspMname(String uspMname) {
		this.uspMname = uspMname;
	}

	public String getUspMobileNo() {
		return this.uspMobileNo;
	}

	public void setUspMobileNo(String uspMobileNo) {
		this.uspMobileNo = uspMobileNo;
	}

	public String getUspPassword() {
		return this.uspPassword;
	}

	public void setUspPassword(String uspPassword) {
		this.uspPassword = uspPassword;
	}

	public String getUspStatus() {
		return this.uspStatus;
	}

	public void setUspStatus(String uspStatus) {
		this.uspStatus = uspStatus;
	}

	public String getUspTelNo() {
		return this.uspTelNo;
	}

	public void setUspTelNo(String uspTelNo) {
		this.uspTelNo = uspTelNo;
	}

	public String getUspTitle() {
		return this.uspTitle;
	}

	public void setUspTitle(String uspTitle) {
		this.uspTitle = uspTitle;
	}

	public String getUspUserName() {
		return this.uspUserName;
	}

	public void setUspUserName(String uspUserName) {
		this.uspUserName = uspUserName;
	}

	public Short getUspWrongLoginCounter() {
		return this.uspWrongLoginCounter;
	}

	public void setUspWrongLoginCounter(Short uspWrongLoginCounter) {
		this.uspWrongLoginCounter = uspWrongLoginCounter;
	}
	
	//Extended Fields
	@Override
	@Transient
	public String getFirstName() {
		return uspFname;
	}

	@Override
	@Transient
	public String getLastName() {
		return uspLname;
	}

	@Override
	@Transient
	public String getPassword() {
		return uspPassword;
	}

	@Override
	@Transient
	public String getUsername() {
		return uspUserName;
	}

	@Override
	@Transient
	public void setFirstName(String firstName) {
		uspFname = firstName;
	}

	@Override
	@Transient
	public void setLastName(String lastName) {
		uspLname = lastName;
	}

	@Override
	@Transient
	public void setPassword(String password) {
		uspPassword = password;
	}

	@Override
	@Transient
	public void setUsername(String username) {
		uspUserName = username;
	}
	@Transient
	private Set<String> privileges;
	
	@Override
	@Transient
	public Set<String> getPrivileges() {
		return this.privileges;
	}	
	@Override
	@Transient
	public void setPrivileges(Set<String> privileges) {
		this.privileges = privileges;
	}

	@Transient
	private String role;
	
	@Override
	@Transient
	public String getRole() {
		return role;
	}
	@Transient
	@Override
	public void setRole(String role) {
		this.role = role;
	}
	
	@Transient
	private String passwordExpired;
	
	@Transient
	public String getPasswordExpired() {
		return passwordExpired;
	}
	@Transient
	public void setPasswordExpired(String passwordExpired) {
		this.passwordExpired = passwordExpired;
	}
	
	@Transient
	private String userGroup;
	
	@Transient
	public String getUserGroup() {
		return userGroup;
	}
	@Transient
	public void setUserGroup(String userGroup) {
		this.userGroup = userGroup;
	}

	public MasterBranch getMasterBranch() {
		return masterBranch;
	}

	public void setMasterBranch(MasterBranch masterBranch) {
		this.masterBranch = masterBranch;
	}

	public MasterCompany getMasterCompany() {
		return masterCompany;
	}

	public void setMasterCompany(MasterCompany masterCompany) {
		this.masterCompany = masterCompany;
	}

	public MasterTemplateGroupToUsp getMasterTemplateGroupToUsp() {
		return masterTemplateGroupToUsp;
	}

	public void setMasterTemplateGroupToUsp(
			MasterTemplateGroupToUsp masterTemplateGroupToUsp) {
		this.masterTemplateGroupToUsp = masterTemplateGroupToUsp;
	}

	public Integer getApproverUspId() {
		return approverUspId;
	}

	public void setApproverUspId(Integer approverUspId) {
		this.approverUspId = approverUspId;
	}
	
}